
# 实现链表
class Node(object):
    def __init__(self,x):
        self.val = x
        self.next = None
class SLinkedList:
    def __init__(self):
        self._head = None
    def is_empty(self):
        return self._head is None

    #   在链表的末尾插入
    def append(self,item):
        node = Node(item)
        if self.is_empty():
            self._head = node
        else:
            cur = self._head
            while cur.next is not None:
                cur = cur.next
            cur.next = node

class output_info(object):
    def __init__(self):
        self.old_point = None
        self.new_point = None
        self.if_avoid_success = None
        self.Unid = None


def output(if_avoid, pipList, pip_info):

    one_group_pipelines = []
    if if_avoid == 1:
        for i in range(len(pipList)):
            current_pip_info = output_info()
            current_pip_info.if_avoid_success = if_avoid
            current_pip_info.new_point = pipList[i]
            one_group_pipelines.append(current_pip_info)
    elif if_avoid ==2:
        for i in range(len(pipList)):
            current_pip_info = output_info()
            current_pip_info.if_avoid_success = if_avoid
            current_pip_info.old_point = pipList[i]
            current_pip_info.Unid = pip_info[i]
            one_group_pipelines.append(current_pip_info)

    return one_group_pipelines

def PipeListNo_to_info(PipeGroupNo,PipeListNo,pipeBase):
    a = []
    for PipeGroup in pipeBase._pipeGroups:
        if PipeGroup.pipeGroupNo == PipeGroupNo:
            for pipeList in PipeGroup._pipeLists:
                if pipeList.pipeListNo == PipeListNo:
                    for pipe in pipeList._pipes:
                        a.append(pipe.uid)
    return a
import openpyxl
def out_excel(link,path):
    wb1 = openpyxl.Workbook()
    wb2 = openpyxl.Workbook()
    ws1 = wb1.active
    ws2 = wb2.active
    ws1.append(['管道组号','是否避障成功','避障后起点终点'])
    ws2.append(['管道组号', '是否避障成功', '原管道起点终点', '原管道id'])
    i= 1
    is_avoid_success = False
    is_avoid_failed = False
    for index in link:
        for current_node in index:
            if current_node.if_avoid_success == 1:
                is_avoid_success = True
                ws1.append([i,'避障成功',
                               str([(current_node.new_point)[0],(current_node.new_point)[1],(current_node.new_point)[2],(current_node.new_point)[3]])])
            elif current_node.if_avoid_success == 2:
                is_avoid_failed = True
                ws2.append([i, '避障失败',
                               str([(current_node.old_point)[0], (current_node.old_point)[1],
                                    (current_node.old_point)[2], (current_node.old_point)[3]])
                                  , current_node.Unid])
        i += 1
    if not is_avoid_success:
        ws1.append(['没有管道进行避障'])
    if not is_avoid_failed:
        ws2.append(['没有管道避障避障失败'])
    wb1.save(path+"/avoiding_obstacles_success.xlsx")
    wb2.save(path+"/avoiding_obstacles_failed.xlsx")